<template>
  <div id="centerLeft1">
    <div class="bg-color-black">
      <div class="d-flex pt-2 pl-2">
        <span>
          <icon name="chart-bar" class="text-icon"></icon>
        </span>
        <div class="d-flex">
          <span class="fs-xl text mx-2">本月最佳店铺</span>
          <dv-decoration-3 class="dv-dec-3" />
        </div>
      </div>
      <div class="d-flex jc-center">
        <div class="bottom-data">
          <div
            class="item-box mt-2"
            v-for="(item, index) in monthNumberData"
            :key="index"
          >
            <div class="d-flex" v-if="item.text === '店铺' && monthCustomer !== ''">
              <span class="coin">{{ item.number.prefix ? item.number.prefix : '' }}</span>
              <el-tooltip class="item" effect="dark" :content="`客户: ${monthCustomer}; 所属部门: ${monthDept}`" placement="top-start">
                <dv-digital-flop class="dv-digital-flop" :config="item.number" />
              </el-tooltip>
            </div>
            <div class="d-flex" v-else>
              <span class="coin">{{ item.number.prefix ? item.number.prefix : '' }}</span>
              <dv-digital-flop class="dv-digital-flop" :config="item.number" />
            </div>
            <p class="text" style="text-align: center;">
              {{ item.text }}
              <span class="colorYellow"></span>
            </p>
          </div>
        </div>
      </div>

      <div class="d-flex pt-2 pl-2" style="margin-top: 40px">
        <span>
          <icon name="chart-bar" class="text-icon"></icon>
        </span>
        <div class="d-flex">
          <span class="fs-xl text mx-2">今日最佳店铺</span>
          <dv-decoration-3 class="dv-dec-3" />
        </div>
      </div>
      <div class="d-flex jc-center">
        <div class="bottom-data">
          <div
            class="item-box mt-2"
            v-for="(item, index) in dayNumberData"
            :key="index"
          >
            <div class="d-flex" v-if="item.text === '店铺' && dayCustomer !== ''">
              <span class="coin">{{ item.number.prefix ? item.number.prefix : '' }}</span>
              <el-tooltip class="item" effect="dark" :content="`客户: ${dayCustomer}; 所属部门: ${dayDept}`" placement="top-start">
                <dv-digital-flop class="dv-digital-flop" :config="item.number" />
              </el-tooltip>
            </div>
            <div class="d-flex" v-else>
              <span class="coin">{{ item.number.prefix ? item.number.prefix : '' }}</span>
              <dv-digital-flop class="dv-digital-flop" :config="item.number" />
            </div>
            <p class="text" style="text-align: center;">
              {{ item.text }}
              <span class="colorYellow"></span>
            </p>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import CenterLeft1Chart from '@/components/echart/centerLeft/centerLeft1Chart'
import { bestShop } from "@/api/statics/dataview";
import { dateFormat } from "@/util/date";
export default {
  data() {
    return {
      dayNumberData: [
        {
          number: {
            number: [0],
            toFixed: 1,
            textAlign: 'left',
            content: '{nt}',
            style: {
              fontSize: 24
            },
            prefix: '￥'
          },
          text: '销售额'
        },
        {
          number: {
            number: [''],
            toFixed: 1,
            textAlign: 'left',
            content: '{nt}',
            style: {
              fontSize: 24
            }
          },
          text: '店铺'
        },
        {
          number: {
            number: [0],
            toFixed: 0,
            textAlign: 'left',
            content: '{nt}',
            style: {
              fontSize: 24
            }
          },
          text: '订单数'
        },
        {
          number: {
            number: [0],
            toFixed: 2,
            textAlign: 'left',
            content: '{nt}',
            style: {
              fontSize: 24
            },
            prefix: '￥'
          },
          text: '利润'
        },
      ],
      monthNumberData: [
        {
          number: {
            number: [0],
            toFixed: 2,
            textAlign: 'left',
            content: '{nt}',
            style: {
              fontSize: 24
            },
            prefix: '￥'
          },
          text: '销售额'
        },
        {
          number: {
            number: [''],
            toFixed: 0,
            textAlign: 'left',
            content: '{nt}',
            style: {
              fontSize: 24
            }
          },
          text: '店铺'
        },
        {
          number: {
            number: [0],
            toFixed: 0,
            textAlign: 'left',
            content: '{nt}',
            style: {
              fontSize: 24
            }
          },
          text: '订单数'
        },
        {
          number: {
            number: [0],
            toFixed: 2,
            textAlign: 'left',
            content: '{nt}',
            style: {
              fontSize: 24
            },
            prefix: '￥'
          },
          text: '利润'
        }
      ],
      dayCustomer: '',
      dayDept: '',
      monthCustomer: '',
      monthDept: '',
    }
  },
  components: {
    CenterLeft1Chart
  },
  mounted() {
    this.changeTiming()
    this.getBestShop()
  },
  methods: {
    getBestShop() {
      const todayParams = {
        startTime: dateFormat(new Date()),
        endTime: dateFormat(new Date())
      }
      bestShop(todayParams).then(res => {
        const data = res.data.data
        if (Object.keys(data).length === 0) {
          return
        }
        this.dayCustomer = data.shopInfo && data.shopInfo.customer ? data.shopInfo.customer : ''
        this.dayDept = data.shopInfo && data.shopInfo.customer ? data.shopInfo.customer : ''
        this.dayNumberData.forEach((item, index) => {
          if (item.text === '店铺') {
            item.number.content = data.name
          }
          if (item.text === '销售额') {
            item.number.number[0] = data.amount
          }
          if (item.text === '利润') {
            item.number.number[0] = data.profit
          }
          if (item.text === '订单数') {
            item.number.number[0] = data.ticketCount
          }
          item.number = { ...item.number }
        })
      })

      const start = new Date()
      start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
      const monthParams = {
        startTime: dateFormat(start),
        endTime: dateFormat(new Date())
      }
      bestShop(monthParams).then(res => {
        const data = res.data.data
        if (Object.keys(data).length === 0) {
          return
        }
        this.monthCustomer = data.shopInfo && data.shopInfo.customer ? data.shopInfo.customer : ''
        this.monthDept = data.shopInfo && data.shopInfo.dept ? data.shopInfo.dept : ''
        this.monthNumberData.forEach((item, index) => {
          if (item.text === '店铺') {
            item.number.content = data.name
          }
          if (item.text === '销售额') {
            item.number.number[0] = data.amount
          }
          if (item.text === '利润') {
            item.number.number[0] = data.profit
          }
          if (item.text === '订单数') {
            item.number.number[0] = data.ticketCount
          }
          item.number = { ...item.number }
        })
      })
    },
    changeTiming() {
      setInterval(() => {
        this.getBestShop()
      }, 30000)
    }
  }
}
</script>

<style lang="scss" scoped>
$box-width: 300px;
$box-height: 410px;

#centerLeft1 {
  padding: 16px;
  height: $box-height;
  width: $box-width;
  border-radius: 10px;
  .bg-color-black {
    height: $box-height - 30px;
    border-radius: 10px;
  }
  .text {
    color: #c3cbde;
  }
  .dv-dec-3 {
    position: relative;
    width: 100px;
    height: 20px;
    top: -3px;
  }

  .bottom-data {
    .item-box {
      & > div {
        padding-right: 5px;
      }
      font-size: 14px;
      float: right;
      position: relative;
      width: 50%;
      color: #d3d6dd;
      .dv-digital-flop {
        width: 120px;
        height: 30px;
      }
      // 金币
      .coin {
        position: relative;
        top: 6px;
        font-size: 20px;
        color: #ffc107;
      }
      .colorYellow {
        color: yellowgreen;
      }
      p {
        text-align: center;
      }
    }
  }
}
</style>
